﻿using System;
using System.Collections.Generic;
using System.Text;
namespace BTSDecompress.ClassLibrary
{
    public class SqlQuery
    {
        #region Variables
        bool _blankLineBetweenRecords;
        string _commandText;
        System.Collections.Hashtable _customFunctions = new System.Collections.Hashtable();
        string _database;
        string _databaseServer;
        bool _hideOuterXMLTag;
        bool _hideContextPropertyNames;
        string _file = "";
        System.Collections.Hashtable _namespaces = new System.Collections.Hashtable();
        string _outputFile = "";
        bool _overwriteOutputFile = false;
        bool _saveSettings;
        bool _showComments;
        int _showMaxNrOfRecords = 0;
        bool _showColumnNames;
        bool _useFieldSeparator;
        bool _wordWrap;
        #endregion
        #region Constructors
        public SqlQuery()
        {
        }
        #endregion
        #region Properties
        public bool BlankLineBetweenRecords
        {
            get
            {
                return _blankLineBetweenRecords;
            }
            set
            {
                _blankLineBetweenRecords = value;
            }
        }
        public string CommandText
        {
            get
            {
                return _commandText;
            }
            set
            {
                _commandText = value;
            }
        }
        public System.Collections.Hashtable CustomFunctions
        {
            get
            {
                return _customFunctions;
            }
            set
            {
                _customFunctions = value;
            }
        }
        public string Database
        {
            get
            {
                return _database;
            }
            set
            {
                _database = value;
            }
        }
        public string DatabaseServer
        {
            get
            {
                return _databaseServer;
            }
            set
            {
                _databaseServer = value;
            }
        }
        public string File
        {
            get
            {
                return _file;
            }
            set
            {
                _file = value;
            }
        }
        public string FullText
        {
            get
            {
                return GetFullText();
            }
        }
        public System.Collections.Hashtable Namespaces
        {
            get { return _namespaces; }
            set { _namespaces = value; }
        }
        public bool HideOuterXMLTag
        {
            get
            {
                return _hideOuterXMLTag;
            }
            set
            {
                _hideOuterXMLTag = value;
            }
        }
        public bool HideContextPropertyNames
        {
            get
            {
                return _hideContextPropertyNames;
            }
            set
            {
                _hideContextPropertyNames = value;
            }
        }
        public string OutputFile
        {
            get
            {
                return _outputFile;
            }
            set
            {
                _outputFile = value;
            }
        }
        public bool OverwriteOutputFile
        {
            get
            {
                return _overwriteOutputFile;
            }
            set
            {
                _overwriteOutputFile = value;
            }
        }
        public bool SaveSettings
        {
            get
            {
                return _saveSettings;
            }
            set
            {
                _saveSettings = value;
            }
        }
        public bool ShowComments
        {
            get
            {
                return _showComments;
            }
            set
            {
                _showComments = value;
            }
        }
        public int ShowMaxNrOfRecords
        {
            get
            {
                return _showMaxNrOfRecords;
            }
            set
            {
                _showMaxNrOfRecords = value;
            }
        }
        public bool ShowColumnNames
        {
            get
            {
                return _showColumnNames;
            }
            set
            {
                _showColumnNames = value;
            }
        }
        public bool UseFieldSeparator
        {
            get
            {
                return _useFieldSeparator;
            }
            set
            {
                _useFieldSeparator = value;
            }
        }
        public bool WordWrap
        {
            get
            {
                return _wordWrap;
            }
            set
            {
                _wordWrap = value;
            }
        }
        #endregion
        #region Methods
        public  void Clear()
        {
            BlankLineBetweenRecords= false;
            CommandText="";
            CustomFunctions = new System.Collections.Hashtable();
            Database="";
            DatabaseServer = "";
            Namespaces = new System.Collections.Hashtable();
            HideOuterXMLTag = false;
            HideContextPropertyNames = false;
            SaveSettings = false;
            ShowComments = false;
            ShowMaxNrOfRecords = 0;
            ShowColumnNames = false;
            UseFieldSeparator = false;
            WordWrap=false;
        }
        private  string GetFullText()
        {
            string fullText="";
            fullText = string.Format(@"-- BTSDecompress Settings
-- Database Server             : {0}
-- Database                    : {1}
{2}-- Hide Outer XML Tag          : {3}
-- Hide Context Property Names : {4}
-- Show Comments               : {5}
-- Save Settings               : {6}
-- Show Column Names           : {7}
-- Use Field Seperator         : {8}
-- Blank line between records  : {9}
-- Word Wrap                   : {10}
-- Show max nr. of records     : {11}
{12}", DatabaseServer, Database,
         NamespacesToText(), HideOuterXMLTag.ToString(), HideContextPropertyNames.ToString(),
         ShowComments.ToString(), SaveSettings.ToString(), ShowColumnNames.ToString(),
         UseFieldSeparator.ToString(), BlankLineBetweenRecords.ToString(), WordWrap.ToString(),
         ShowMaxNrOfRecords.ToString(), CommandText);
            
            return fullText;
        }
        private  string NamespacesToText()
        {
            string namespaces = "";

            foreach (System.Collections.DictionaryEntry entry in _namespaces)
            {
                namespaces += string.Format("-- Namespace                   : {0} {1}\r\n", entry.Key, entry.Value);
            }
            return namespaces;
        }
        #endregion
    }
}
